package com.bosssoft.boss_exam_core.common.token;


import com.bosssoft.boss_exam_core.util.common.CharUtil;
import com.bosssoft.boss_exam_core.util.common.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;

//import com.cherish_lailai.cherishmall.db.entity.UserLys;
//import com.cherish_lailai.cherishmall.db.service.IUserLysService;


public class UserTokenRedisManager implements ITokenManager {

    private  Long timeout;

    public Long getTimeout() {
        return timeout;
    }

    public void setTimeout(Long timeout) {
        this.timeout = timeout;
    }

    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    @Override
    public String getUserId(String token) {
        return null;
    }

    @Override
    public UserToken generateToken(String id) {
        String token = CharUtil.getRandomString(32);
        LocalDateTime update = LocalDateTime.now();
        LocalDateTime expire = update.plusDays(1);
        UserToken userToken = new UserToken();
        userToken.setToken(token);
        userToken.setUpdateTime(update);
        userToken.setExpireTime(expire);
        userToken.setUserId(id);
        return userToken;
    }
}
